﻿using Landpy.CruiseControlNet.ConfigurationSidekick.ConfigTreeModule;
using System;
using Landpy.CruiseControlNet.FacadeInterface.RepositoryModule;
using Landpy.CruiseControlNet.Infrastructure.Ioc;

namespace Landpy.CruiseControlNet.ConfigurationSidekick.ConfigPropertyModule
{
    abstract class GetPropertiesHandler : IGetPropertiesHandler
    {
        protected IProjectRepository ProjectRepository { get; private set; }
        protected ISecurityUserRepository SecurityUserRepository { get; private set; }
        protected IPermissionRepository PermissionRepository { get; private set; }
        protected IPublisherRepository PublisherRepository { get; private set; }
        protected ITaskRepository TaskRepository { get; private set; }
        protected ISubjectRepository SubjectRepository { get; private set; }
        protected IAssemblyRepository AssemblyRepository { get; private set; }
        protected IEmailGroupRepository EmailGroupRepository { get; private set; }
        protected IEmailUserRepository EmailUserRepository { get; private set; }
        protected ITriggerRepository TriggerRepository { get; private set; }
        protected IXslFileRepository XslFileRepository { get; private set; }
        protected ISourceControlRepository SourceControlRepository { get; private set; }
        public IGetPropertiesHandler Successor { set; protected get; }

        protected GetPropertiesHandler()
        {
            this.ProjectRepository = IOC.GetInstance().ApplicationContext["ProjectRepository"] as IProjectRepository;
            this.SecurityUserRepository = IOC.GetInstance().ApplicationContext["SecurityUserRepository"] as ISecurityUserRepository;
            this.PermissionRepository = IOC.GetInstance().ApplicationContext["PermissionRepository"] as IPermissionRepository;
            this.PublisherRepository = IOC.GetInstance().ApplicationContext["PublisherRepository"] as IPublisherRepository;
            this.TaskRepository = IOC.GetInstance().ApplicationContext["TaskRepository"] as ITaskRepository;
            this.SubjectRepository = IOC.GetInstance().ApplicationContext["SubjectRepository"] as ISubjectRepository;
            this.AssemblyRepository = IOC.GetInstance().ApplicationContext["AssemblyRepository"] as IAssemblyRepository;
            this.EmailGroupRepository = IOC.GetInstance().ApplicationContext["EmailGroupRepository"] as IEmailGroupRepository;
            this.EmailUserRepository = IOC.GetInstance().ApplicationContext["EmailUserRepository"] as IEmailUserRepository;
            this.TriggerRepository = IOC.GetInstance().ApplicationContext["TriggerRepository"] as ITriggerRepository;
            this.XslFileRepository = IOC.GetInstance().ApplicationContext["XslFileRepository"] as IXslFileRepository;
            this.SourceControlRepository = IOC.GetInstance().ApplicationContext["SourceControlRepository"] as ISourceControlRepository;
        }

        public abstract object GetPropertiesObject(GetPropertiesContext getPropertiesContext);

        protected TreeNodeIndentity GetTreeNodeIndentity(GetPropertiesContext getPropertiesContext)
        {
            var treeNodeIndentity = new TreeNodeIndentity(TreeNodeType.Unknow, String.Empty);
            if (getPropertiesContext.TreeNode.Tag != null)
            {
                treeNodeIndentity = (TreeNodeIndentity)getPropertiesContext.TreeNode.Tag;
            }
            return treeNodeIndentity;
        }
    }
}
